<template>
  <div class="update-gender">
    <van-picker
      title="修改性别"
      show-toolbar
      :columns="columns"
      :default-index="localGender"
      @confirm="onConfirm"
      @cancel="$emit('close')"
      @change="onChange"
    />
  </div>
</template>

<script>
import { updateUserName } from './update-name.vue'
export default {
  name: 'UpdateGender',
  components: {

  },
  data () {
    return {
      columns: [
        // 第一列
        {
          values: ['周一', '周二', '周三', '周四', '周五'],
          defaultIndex: 2
        },
        // 第二列
        {
          values: ['上午', '下午', '晚上'],
          defaultIndex: 1
        }
      ]
    }
  },
  created () {

  },
  methods: {
    async onClickRight () {
      this.$toast.loading({
        message: '保存中...',
        forbidClick: true,
        duration: 0
      })
      try {
        await updateUserName({
          gender: this.localGender
        })
        // 修改父组件的昵称
        this.$emit('input', this.localGender)
        // 关闭弹出层
        this.$emit('close')
        this.$toast('修改成功！')
      } catch (e) {
        this.$toast('修改失败！')
      }
    }
  }
}
</script>

<style lang="less" scoped>

</style>
